' UNMANAGEDAPI.VB
' Unmanaged API Class for Cold Storage.
'
' Copyright (C) 2002 Microsoft Corporation 
' All rights reserved. 
'
' THIS CODE AND INFORMATION IS PROVIDED "AS IS" 
' WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, 
' INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF 
' MERCHANTIBILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE. 
' 
' Date: 03/13/02
' Authors: Allen Wagner, Marcelo Uemura, David Willson

Option Explicit On 

Imports System
Imports System.Runtime.InteropServices
Public Class Shell32

    Public Const MAX_PATH As Integer = 256

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure SHITEMID

        <MarshalAs(UnmanagedType.LPArray)> _
            Public cb As System.UInt16
        Public abID() As Byte

    End Structure

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure ITEMIDLIST

        Public mkid As SHITEMID

    End Structure

    <StructLayout(LayoutKind.Sequential)> _
        Public Structure BROWSEINFO

        Public hwndOwner As IntPtr
        Public pidlRoot As IntPtr
        Public pszDisplayName As IntPtr
        <MarshalAs(UnmanagedType.LPTStr)> _
            Public lpszTitle As String
        Public ulFlags As System.UInt32
        Public lpfn As IntPtr
        Public lParam As Integer
        Public iImage As IntPtr

    End Structure

    ' Browsing for directory.
    ' Note: Function System.Convert.ToUInt32 is not CLS Compliant.
    Public Shared BIF_RETURNONLYFSDIRS As System.UInt32 = _
        Convert.ToUInt32(&H1)
    Public Shared BIF_DONTGOBELOWDOMAIN As System.UInt32 = _
        Convert.ToUInt32(&H2)
    Public Shared BIF_STATUSTEXT As System.UInt32 = _
        Convert.ToUInt32(&H4)
    Public Shared BIF_RETURNFSANCESTORS As System.UInt32 = _
        Convert.ToUInt32(&H8)
    Public Shared BIF_EDITBOX As System.UInt32 = _
        Convert.ToUInt32(&H10)
    Public Shared BIF_VALIDATE As System.UInt32 = _
        Convert.ToUInt32(&H20)
    Public Shared BIF_NEWDIALOGSTYLE As System.UInt32 = _
        Convert.ToUInt32(&H40)
    Public Shared BIF_USENEWUI As System.UInt32 = _
        Convert.ToUInt32(&H50)
    Public Shared BIF_BROWSEINCLUDEURLS As System.UInt32 = _
        Convert.ToUInt32(&H80)
    Public Shared BIF_BROWSEFORCOMPUTER As System.UInt32 = _
        Convert.ToUInt32(&H1000)
    Public Shared BIF_BROWSEFORPRINTER As System.UInt32 = _
        Convert.ToUInt32(&H2000)
    Public Shared BIF_BROWSEINCLUDEFILES As System.UInt32 = _
        Convert.ToUInt32(&H4000)
    Public Shared BIF_SHAREABLE As System.UInt32 = _
        Convert.ToUInt32(&H8000)

    Public szDisplayName As String

    <StructLayout(LayoutKind.Sequential)> _
    Public Structure SHFILEINFO

        Public hIcon As IntPtr
        Public iIcon As Integer
        Public dwAttributes As System.UInt32
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=260)> _
        Public szDisplayName As String
        <MarshalAs(UnmanagedType.ByValTStr, SizeConst:=80)> _
        Public szTypeName As String

    End Structure

    ' Get Icon
    Public Shared SHGFI_ICON As System.UInt32 = _
        Convert.ToUInt32(&H100)
    ' Get Display Name
    Public Shared SHGFI_DISPLAYNAME As System.UInt32 = _
        Convert.ToUInt32(&H200)
    ' Get Type Name
    Public Shared SHGFI_TYPENAME As System.UInt32 = _
        Convert.ToUInt32(&H400)
    ' Get Attributes
    Public Shared SHGFI_ATTRIBUTES As System.UInt32 = _
        Convert.ToUInt32(&H800)
    ' Get Icon Location
    Public Shared SHGFI_ICONLOCATION As System.UInt32 = _
        Convert.ToUInt32(&H1000)
    ' Return Executable Type
    Public Shared SHGFI_EXETYPE As System.UInt32 = _
        Convert.ToUInt32(&H2000)
    ' Get System Icon Index
    Public Shared SHGFI_SYSICONINDEX As System.UInt32 = _
        Convert.ToUInt32(&H4000)
    ' Put a link overlay on the icon.
    Public Shared SHGFI_LINKOVERLAY As System.UInt32 = _
        Convert.ToUInt32(&H8000)
    ' Show the icon in the selected state.
    Public Shared SHGFI_SELECTED As System.UInt32 = _
        Convert.ToUInt32(&H10000)
    ' Get only specified attributes.
    Public Shared SHGFI_ATTR_SPECIFIED As System.UInt32 = _
        Convert.ToUInt32(&H20000)
    ' Get Large Icon
    Public Shared SHGFI_LARGEICON As System.UInt32 = _
        Convert.ToUInt32(&H0)
    ' Get Small Icon
    Public Shared SHGFI_SMALLICON As System.UInt32 = _
        Convert.ToUInt32(&H1)
    ' Get Open Icon
    Public Shared SHGFI_OPENICON As System.UInt32 = _
        Convert.ToUInt32(&H2)
    ' Get Shell Size Icon
    Public Shared SHGFI_SHELLICONSIZE As System.UInt32 = _
        Convert.ToUInt32(&H4)
    ' The pszPath is a PIDL.
    Public Shared SHGFI_PIDL As System.UInt32 = _
        Convert.ToUInt32(&H8)
    ' Use Passed dwFileAttribute
    Public Shared SHGFI_USEFILEATTRIBUTES As System.UInt32 = _
        Convert.ToUInt32(&H10)
    ' Apply the appropriate overlays.
    Public Shared SHGFI_ADDOVERLAYS As System.UInt32 = _
        Convert.ToUInt32(&H20)
    ' Get the index of the overlay.
    Public Shared SHGFI_OVERLAYINDEX As System.UInt32 = _
        Convert.ToUInt32(&H40)

    Public Shared FILE_ATTRIBUTE_DIRECTORY As System.UInt32 = _
        Convert.ToUInt32(&H10)
    Public Shared FILE_ATTRIBUTE_NORMAL As System.UInt32 = _
        Convert.ToUInt32(&H80)

    <DllImport("Shell32.dll")> _
    Public Shared Function SHGetFileInfo( _
    ByVal pszPath As String, _
    ByVal dwFileAttributes As System.UInt32, _
        ByRef psfi As SHFILEINFO, _
    ByVal cbFileInfo As System.UInt32, _
    ByVal uFlags As System.UInt32) As IntPtr
    End Function

    <DllImport("Shell32.dll")> _
    Public Shared Function SHBrowseForFolder( _
        ByRef lpbi As BROWSEINFO) As IntPtr
    End Function

    <DllImport("Shell32.dll")> _
    Public Shared Function SHGetPathFromIDList( _
    ByVal pidl As IntPtr, _
    ByVal pszPath As IntPtr) As System.UInt32
    End Function

End Class

Public Class User32

    <DllImport("User32.dll")> _
    Public Shared Function DestroyIcon( _
        ByVal hIcon As IntPtr) As Integer
    End Function

End Class
